import random
import llm
import database_util
import time
from mylogger import logger

def get_random(arr, n):
    result = random.sample(arr, n)
    return result

def get_random_int(min, max):
    return random.randint(min, max)

def generate_word_of_encourage_QWenAI(storySize=1000):
    # ChatAI = llm.QWenChat()
    ChatAI = llm.SFChat()

    story = ""

    THEMES = [
        "失恋", "挂科", "投资亏损", "比赛失败", "失业", "生病", "破产", "受伤", "出交通事故", "友谊破裂", 
        "梦想破灭", "离婚", "被背叛", "被欺骗", "面试失败", "车坏", "被误解", "创业失败", "转型失败", 
        "考试不及格", "遭受损失", "计划落空", "被解雇", "生病住院", "破产", "遭受伤害", "遭遇交通事故", 
        "友情破裂", "梦想破碎", "婚姻破裂", "背叛", "被欺骗", "面试失败", "汽车损坏", "错过公交车", 
        "电脑崩溃", "迷路", "错过重要的电话或信息", "错过重要的日期", "投资失败", "车子被偷", 
        "错过重要的机会", "被炒鱿鱼", "重要的文件丢失", "考试成绩不及格", "无法完成重要的任务或项目", 
        "无法达到自己的目标或期望", "无法得到自己想要的东西", "无法实现自己的梦想或计划", 
        "无法与自己喜欢的人在一起", "无法获得自己想要的认可"
    ]

    theme = get_random(THEMES, 1)

    prompt_s = f"我{theme[0]}了，请给我{storySize}字左右（很多很多）很感动，很鼓励的话，可以用你的亲身经历，也可以用历史典故，激励我，注意不要闲聊."

    story = ChatAI.startChat(prompt_s)

    return story.strip('"')
                            
                       
def main():
    
    text = generate_word_of_encourage_QWenAI(1500)
    logger.info(text)
    # while True:
    #     try:
    #         text = test_story(2000,500)
    #         count = 0
    #         llm_model = "qwen_max"
    #         version = "story_v2"
    #         database_util.insert_data(text, count, llm_model, version)
    #     except Exception as e:
    #         logger.exception(e)
    #         time.sleep(10)
main()